package com.dv.web.controller.basic;

import com.dv.common.annotation.Log;
import com.dv.common.core.controller.BaseController;
import com.dv.common.core.domain.AjaxResult;
import com.dv.common.core.page.TableDataInfo;
import com.dv.common.enums.BusinessType;
import com.dv.common.utils.DateUtils;
import com.dv.driverless.domain.BasicDepartment;
import com.dv.driverless.service.IBasicDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 运输单位信息Controller
 *
 * @author ruoyi
 * @date 2023-04-06
 */
@RestController
@RequestMapping("/basic/department")
public class BasicDepartmentController extends BaseController {
    @Autowired
    private IBasicDepartmentService basicDepartmentService;

    /**
     * 查询运输单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:department:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicDepartment basicDepartment) {
        startPage();
        List<BasicDepartment> list = basicDepartmentService.selectBasicDepartmentList(basicDepartment);
        return getDataTable(list);
    }

    /**
     * 获取运输单位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:department:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(basicDepartmentService.selectBasicDepartmentById(id));
    }

    /**
     * 新增运输单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:department:add')")
    @Log(title = "运输单位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicDepartment basicDepartment) {
        basicDepartment.setCreateDate(DateUtils.getNowDate());
        return toAjax(basicDepartmentService.insertBasicDepartment(basicDepartment));
    }

    /**
     * 修改运输单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:department:edit')")
    @Log(title = "运输单位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicDepartment basicDepartment) {
        return toAjax(basicDepartmentService.updateBasicDepartment(basicDepartment));
    }

    /**
     * 删除运输单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:department:remove')")
    @Log(title = "运输单位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(basicDepartmentService.deleteBasicDepartmentByIds(ids));
    }
}
